package com.zq.product.controller;


import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.product.dao.dto.CategoryBrandDto;
import com.zq.product.dao.entity.Brand;
import com.zq.product.dao.entity.CategoryBrand;
import com.zq.product.dao.vo.CategoryBrandVO;
import com.zq.product.service.ICategoryBrandService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-05-13
 */
@RestController
@RequestMapping("/product/category-brand")
public class CategoryBrandController {


    @Resource
    private ICategoryBrandService categoryBrandService;




//    查询所有分类品牌
    @GetMapping("/getAll/{page}/{limit}")
    public Result<PageInfo<CategoryBrandVO>> findByPage(@PathVariable Integer page, @PathVariable Integer limit, CategoryBrandDto CategoryBrandDto) {
//        PageInfo<CategoryBrand> pageInfo = categoryBrandService.findByPage(page, limit, CategoryBrandDto);
        PageInfo<CategoryBrandVO> pageInfo = categoryBrandService.findByPage(page, limit, CategoryBrandDto);
        return Result.successData(pageInfo);
    }

//    添加分类品牌
    @PostMapping("/save")
    public Result<String> save(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.save(categoryBrand);
        return Result.success() ;
    }

//    修改分类品牌
    @PutMapping("updateById")
    public Result<String> updateById(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.updateById(categoryBrand);
        return Result.success() ;
    }

    @DeleteMapping("/deleteById/{id}")
    public Result<String> deleteById(@PathVariable Long id) {
        categoryBrandService.removeById(id);
        return Result.success() ;
    }

//    根据分类id查询品牌
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result<Object> findBrandByCategoryId(@PathVariable Long categoryId) {
        List<Brand> brandList =   categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.successData(brandList) ;
    }


}
